#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+10;
int qop[N],qx[N],qy[N];
int nxt[N];
map<pair<int,int>,int> mp;
int son[N][2];
int siz[N];
int fath[N];
bool rtag[N];
void rev(int now){
    rtag[now] ^= 1;
    swap(son[now][0],son[now][1]);
}
void push_down(int now){
    if(rtag[now]){
        rev(son[now][0]);
        rev(son[now][1]);
        rtag[now] = 0;
    }
}
pair<int,int> mi[N];
pair<int,int> val[N];
void push_up(int now){
    mi[now] = val[now];
    siz[now] = 1;
    if(son[now][0]){
        mi[now] = min(mi[now],mi[son[now][0]]);
        siz[now] += siz[son[now][0]];
    }
    if(son[now][1]){
        mi[now] = min(mi[now],mi[son[now][1]]);
        siz[now] += siz[son[now][1]];
    }
}
bool isroot(int x){
    return son[fath[x]][0] != x && son[fath[x]][1] != x;
}
bool get(int x){
    return son[fath[x]][1] == x;
}
void rotate(int x){
    int y = fath[x],z = fath[y];
    push_down(y);
    push_down(x);
    int p = get(x);
    if(!isroot(y)){
        son[z][get(y)] = x;
    }
    fath[x] = z;
    fath[y] = x;
    fath[son[x][p ^ 1]] = y;
    son[y][p] = son[x][p ^ 1];
    son[x][p ^ 1] = y; 
    push_up(y);
    push_up(x);
}
void splay(int x){
    while(!isroot(x)){
        int fa = fath[x];
        if(!isroot(fa)){
            rotate(get(fa) == get(x)?fa:x);
        }
        rotate(x);
    }
}
int access(int x){
    int p = 0;
    while(x){
        splay(x);
        push_down(x);
        son[x][1] = p;
        push_up(x);
        p = x;
        x = fath[x];
    }
    return p;
}
void make_root(int now){
    access(now);
    splay(now);
    rev(now);
}
void link(int x,int y){
    make_root(x);
    fath[x] = y;
}
void split(int x,int y){
    make_root(x);
    access(y);
    splay(x);
}
void cut(int x,int y){
    split(x,y);
    push_down(x);
    son[x][1] = 0;
    fath[y] = 0;
    push_up(x);
}
int find_rot(int x){
    access(x);
    splay(x);
    int p = x;
    push_down(p);
    while(son[p][0]){
        push_down(p);
        p = son[p][0];
    }
    splay(p);
    return p;
}
int pre[N];
int main(){
    int n,m;
    cin>>n>>m;
    for(int i = 1;i <= n + m;i++){
        siz[i] = 1;
        val[i] = make_pair(0x3f3f3f3f,0);
    }
    for(int i = 1;i<=m;i++){
        cin>>qop[i]>>qx[i]>>qy[i];
    }
    for(int i = m;i >= 1;i--){
        if(qop[i] == 1){
            mp[make_pair(qx[i],qy[i])] = i;
            mp[make_pair(qy[i],qx[i])] = i;
        }else if(qop[i] == 0){
            nxt[i] = mp[make_pair(qx[i],qy[i])];
            if(nxt[i]){
                pre[nxt[i]] = i;
            }else{
                nxt[i] = m + 1;
            }
            mp[make_pair(qx[i],qy[i])] = 0;
        }
    }
    for(int i = 1;i<=m;i++){
        if(qop[i] == 0){
            val[i + n] = make_pair(nxt[i],i);
            if(find_rot(qx[i]) == find_rot(qy[i])){
                split(qx[i],qy[i]);
                pair<int,int> val = mi[qx[i]];
                if(val.first < nxt[i]){
                    cut(qx[val.second],val.second + n);
                    cut(qy[val.second],val.second + n);
                    link(qx[i],i + n);
                    link(qy[i],i + n);
                }
            }else{
                link(qx[i],i + n);
                link(qy[i],i + n);
            }
        }else if(qop[i] == 1){
            if(find_rot(qx[i]) == find_rot(pre[i] + n)){
                cut(qx[i],pre[i] + n);
                cut(qy[i],pre[i] + n);
            }
        }else{
            if(find_rot(qx[i]) == find_rot(qy[i])){
                cout<<"Y\n";
            }else{
                cout<<"N\n";
            }
        }
    }
}